const express = require("express");
const url = require("url");
const bodyParser = require("body-parser");

//use()会截取开头的/api，路由路径写/login就行了

const router = new express.Router();

//对ajax进行处理
router.get("/login",(request,response)=>{
    let urlobj = url.parse(request.url,true);
    console.log(urlobj)
    response.status(500).json({
        status: 0,
        message: "登录成功",
        data: {}
    })
})

//bodyParser.urlencoded()中间件内部调用next()   处理post请求的body参数
router.use("/login",bodyParser.urlencoded())

router.post("/login",(request,response)=>{

    //post请求数据在request.body中
    console.log(request.body)

    response.status(500);
    response.json({
        status: 0,
        message: "登录成功",
        data: {}
    })
})

module.exports = router;